<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
			
			<div class="layui-form-item">
				<label class="layui-form-label">添加时间</label>
				<div class="layui-input-block">
					<div class="input-group layui-col-md6">
						<input type="text" class="layui-input" id="create_time" name="create_time" value="{$model.create_time??''}" placeholder="请输入添加时间" class="layui-input"  verify="must">
					</div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">收支项目</label>
				<div class="layui-input-block">
					<div class="input-group layui-col-md3 lay-m-r-30">
					  <div id="cost" {eq name="model.type" value="1"}style="display:none;"{/eq}>
						 <select lay-filter="billname">
							<option value="">请选择或者输入</option>
							{volist name="options.bill_cost" id="v"}
							{if !$action_up}
							<option value="{$v}">{$v}</option>
							{elseif $v == $model.name}
							<option value="{$v}" selected="selected">{$v}</option>
							{else/}
							<option value="{$v}">{$v}</option>
							{/if}
							{/volist}
						</select> 
					  </div>
					  
					  <div id="income" {eq name="model.type" value="0"}style="display:none;"{/eq}>
						 <select lay-filter="billname">
							<option value="">请选择或者输入</option>
							{volist name="options.bill_income" id="v"}
							{if !$action_up}
							<option value="{$v}">{$v}</option>
							{elseif $v == $model.name}
							<option value="{$v}" selected="selected">{$v}</option>
							{else/}
							<option value="{$v}">{$v}</option>
							{/if}
							{/volist}
						</select> 
					  </div>
					</div>
					<div class="input-group layui-col-md6">
						<input type="text" name="name" value="{$model.name??''}" placeholder="请选择货输入收支项目" class="layui-input"  verify="must">
					</div>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">收支类型</label>
				<div class="layui-input-block">
					{volist name="options.bill_type" id="v"}
					{if $v.id == $model.type}
					<input type="radio" name="type" lay-filter="type" title="{$v.val}" value="{$v.id}" checked>
					{else/}
					<input type="radio" name="type" lay-filter="type" title="{$v.val}" value="{$v.id}">
					{/if}
					{/volist}
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">收支金额</label>
				<div class="layui-input-block">
				    <div class="input-group layui-col-md4">
				    <input type="text" id="money" name="money" value="{$model.money??''}" placeholder="请输入收支金额" class="layui-input"  verify="must">
					<span class="input-group-addon">元</span>
					</div>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">收支备注</label>
				<div class="layui-input-block">
				  <textarea name="remark" placeholder="请输入收支备注" class="layui-textarea">{$model.remark??''}</textarea>
				</div>
			</div>
			
			<div class="layui-form-item" style="display: none;">
				<label class="layui-form-label">添加方式</label>
				<div class="layui-input-block">
					<input type="checkbox" lay-skin="switch" value="addtype" lay-text="手动录入|系统生成" {if $model.addtype??1 == 1} checked {/if}><input type="hidden" name="addtype" value="{$model.addtype??1}">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">收支状态</label>
				<div class="layui-input-block">
					<input type="checkbox" lay-skin="switch" value="status" lay-text="启用|禁用" {if $model.status??1 == 1} checked {/if}><input type="hidden" name="status" value="{$model.status??1}">
				</div>
			</div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="save" verify="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
	layui.use(['form', 'jquery', 'uploads','common','mycomm','laydate'], function () {
		let form = layui.form;
		let $ = layui.jquery;
		let common = layui.common;
		let mycomm = layui.mycomm;
		let laydate = layui.laydate;
		var bill_type = 0;
	
		mycomm.editSubmit();
		
		laydate.render({
			elem: '#create_time' ,//指定元素
			value:'{$model.create_time??''}',
			type:'datetime'
		});
		
		form.on('select(billname)', function (data) {
			var name=data.value;
			if(name!='其他' && name!='请选择或输入'){
				$("[name=name]").val(name);
			}else{
				$("[name=name]").val('');
			}
		});
		
		//切换收支选项
		form.on('radio(type)', function (data) {
		　　bill_type = data.value;
			if(bill_type==1){
				$('#income').show();
				$('#cost').hide();
			}else{
				$('#income').hide();
				$('#cost').show();
			}
			update_money();
		});
		
		//自动转换正负数
		$("#money").change(function(){
			update_money();
		});
		
		//自动转换正负数
		function update_money(){
			var money=Math.abs($("#money").val());
			if(money!=''){
				if(bill_type==1){
					$("[name=money]").val(money);
				}else{
					$("[name=money]").val(-money);
				}			
			}
		}
	})
</script>
{$LOAD_STYLE.bottom|raw}

</body>
</html>